// pages/Todayoffer/Todayoffer.js
var tool = require("../Tongyong/tongyong.js");//调取共用类的方法
Page({

  /**
   * 页面的初始数据
   */
  data: {
    loadingHidden: false,
    xuanzebutimage:'../../resources/icon_jiantou_baise.png',
    isselectxuanze:false,
    isgudingheader:false,
    classifyInfo:[],
    companyInfo:{},
    quotationInfo:[],
    visited_num:'',
    classify_id:0,
    selecename:'全部货品',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // console.log(getApp().globalData.xuanzeleixin);
    //调用数据更新方法
    
  },

  /***更新数据方法 */
  getdatarequest: function () {
    var self = this;

    self.setData({
      loadingHidden: false,
    });

    var qingqiudata = {
      classify_id: self.data.classify_id,
      is_page: 0
    }
    tool.Httprequest('getQuotationInfo', qingqiudata, function (res) {
      // console.log(res);

     //定义全部货品
     var quanbu={
       classify_id:0,
       classify_name:"全部货品"
     }

      var classifyInfo=[];
      classifyInfo = res.classifyInfo;
      classifyInfo.unshift(quanbu);

      var companyInfo = res.companyInfo;
      var quotationInfo = res.quotationInfo;
      var visited_num = res.visited_num;
      self.setData({
        classifyInfo: classifyInfo,
        companyInfo: companyInfo,
        quotationInfo: quotationInfo,
        visited_num: visited_num,
      })
    }, function (res) {
      console.log(res);
    }, function (res) {

      self.setData({
        loadingHidden: true,
      });
      wx.stopPullDownRefresh();
    })
  },


//选择顶部菜单按钮方法
  xuanzeAction:function (e){
    var that=this;
    var isxuanzhong = that.data.isselectxuanze;
    if(isxuanzhong==true){
       that.setData({
         xuanzebutimage: '../../resources/icon_jiantou_baise.png',
         isselectxuanze: false,
         isscroll:true,
       })
    }else{
      that.setData({
        xuanzebutimage: '../../resources/icon_jiantou_1_baise.png',
        isselectxuanze: true,
        isscroll: false,
      })
    }
  },

//选择名称的方法 将选中的id进行存储 供查询列表使用
  xuanzeclassnameAction:function(e){
    var classID = e.target.dataset.classid;
    var classname = e.target.dataset.classname;
    var self=this;
    self.setData({
      classify_id: classID,
      selecename:classname
    });
    //调用接口查询数据
    this.getdatarequest();

  },

  // scrollviewAction:function(e){
  //   console.log(e)
  //   var that = this;

  //   if (e.currentTarget.dataset.name=="bigsc")
  //   {
  //   var isxuanzhong = that.data.isselectxuanze;
  //   if (isxuanzhong == true) {
  //     that.setData({
  //       xuanzebutimage: '../../resources/icon_jiantou_baise.png',
  //       isselectxuanze: false,
  //       isscroll: true,
  //     })
  //   }

  //   if (e.detail.scrollTop > 110) {
  //     that.setData({
  //       isgudingheader: true
  //     })
  //   } else {
  //     that.setData({
  //       isgudingheader: false
  //     })
  //   }

  //   }
  // },
  
  //内部小块的滑动
  classscrollviewAction:function(e){

  },

  //询价按钮
  xunjiaAction: function (e) {
    wx.navigateTo({
      url: '../Xunjiajilu/Xunjiajilu',
    })
  },

  onPageScroll: function (e) { // 获取滚动条当前位置
    console.log(e)

   var that=this;
    var isxuanzhong = that.data.isselectxuanze;
    if (isxuanzhong == true) {
      that.setData({
        xuanzebutimage: '../../resources/icon_jiantou_baise.png',
        isselectxuanze: false,
        isscroll: true,
      })
    }

    if (e.scrollTop > 110) {
      that.setData({
        isgudingheader: true
      })
    } else {
      that.setData({
        isgudingheader: false
      })
    }


  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    console.log('iiiiiiii');
    var self=this;
    if (getApp().globalData.xuanzeID !=0){
      self.setData({
        classify_id: getApp().globalData.xuanzeID,
        selecename: getApp().globalData.xuanzeleixin
      });
    }
    self.getdatarequest();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
     console.log('页面关闭了')
     getApp().globalData.xuanzeID = 0;
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    var self=this;

    var isxuanzhong = self.data.isselectxuanze;
    if (isxuanzhong == true) {
      self.setData({
        xuanzebutimage: '../../resources/icon_jiantou_baise.png',
        isselectxuanze: false,
        isscroll: true,
      })
    }
    
    self.getdatarequest();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})